layui.config({
    base : "/dhjdglxt/modules/util/"//自定义加载的模块
}).use(['form', 'layer', 'jquery', 'layedit', 'laydate', 'laypage', 'table', 'upload', 'commUtil', 'element'], function () {
    var form = layui.form,
        layer = parent.layer === undefined ? layui.layer : parent.layer,
        laypage = layui.laypage,
        layedit = layui.layedit,
        laydate = layui.laydate,
        upload = layui.upload,
        $ = layui.jquery;
    var table = layui.table;
    var commUtil = layui.commUtil;
    var element = layui.element;
    var submitType="submit";
    
    var flowRecId=$("#recId").val();
    //材料列表，办理日志
    var processLogPage_url = basePath + '/modules/airplanebaseinfo/oa/processLogList.jsp?flowRecId=' + flowRecId;
    var stuffPage_url = basePath + '/modules/airplanebaseinfo/oa/stuffList.jsp?flowRecId=' + $("#flowRecId").val();
    $('#processLogPage').attr('src', processLogPage_url);
    $('#stuffPage').attr('src', stuffPage_url);
    
    //每次点击材料列表，需要重新加载
    element.on('tab(tabs)', function (data) {
        if (data.index == 1) {
            $('#stuffPage').attr('src', stuffPage_url);
        } 
    });
    
    
    var unitCode='';
    layer.ready(function () {
 	  
 });
    

    $("#airplanEdit").click(function(){
    	 $.ajax({
             type: "GET",
             url: basePath + '/service/airplanebaseinfo/airplanebaseinfo/getBlPage',
             data: {
                 recId: $("#recId").val()
             },
             async: false,
             success: function (data) {
                 if (data.data != undefined) {
               	  layer.open({
               		  type: 2,
               		  title: '办理详情',
               		  shadeClose: true,
               		  shade: 0.8,
               		  offset: '50px',
               		  area: ['90%', '90%'],
               		  content: data.data + "?flowOptTag=" + $("#recId").val() + "&flowInstId=" + $("#recId").val()+"&transContent="+parent.$("#transContents").val()
               		}); 
                 }
             }
         });
	 });
    
    $("#moduleSubmit").click(function(){
    	 var users = $("#nextUser").val();
	        var parms = "";
	        var title = ""
	        parms = "type=users&value=nextUser&name=nextUserName&chkType=radio";
	        title = "流程人员选择选择";
	        openGneDiv("380px", "400px", basePath + "/service/ztree/ztreeInfo?" + parms, title);
    });
    $("#flowEnd").click(function(){
    	 layer.confirm('是否飞机完成引进？', {
             btn: ['确认','取消'] //按钮
       , offset: '30px'
       }, function(){
    	   $.ajax({ 
 		        type: "POST",
 		        url: basePath+'/service/airplanebaseinfo/airplanebaseinfo/checkAirplane',
 		        data:{ recId:$("#recId").val()},
 		        async:false,
 		        dataType: "json",
 		        success: function(data){
 		        	if(data.code=='0'){
 		        		if(data.data=='0'){
 		        		  $("#flowState").val("End");
 		        		  $.ajax({ 
 		        		        type: "POST",
 		        		        url: basePath+'/service/airplanebaseinfo/airplanebaseinfo/submitFlow',
 		        		        data: $("#viewForm").serialize(),
 		        		        async:false,
 		        		        dataType: "json",
 		        		        success: function(data){
 		        		        	if(data.code=='0'){
 		        		        		layer.msg("操作成功", {icon: 1});
 		        		        		 parent.location.reload();	
 		        		    		} else {
 		        		    			layer.msg("操作失败", {icon: 0});
 		        		    		}
 		        		        }
 		        		    });
 		        		} else {
 	 		    			layer.msg(data.data, {icon: 0});
 	 		    		}
 		    		} else {
 		    			layer.msg(data.data, {icon: 0});
 		    		}
 		        }
 		    });
    	   
    	   
    	   
    	   
    	 
      	 
      	 
           }, function(){

           });
    });
    $("#flowEndRc").click(function(){
   	 layer.confirm('您是否要结束运维流程？', {
            btn: ['确认','取消'] //按钮
      , offset: '30px'
      }, function(){
   	   $("#flowState").val("EndRc");
     	 $.ajax({ 
 		        type: "POST",
 		        url: basePath+'/service/airplanebaseinfo/airplanebaseinfo/submitFlow',
 		        data: $("#viewForm").serialize(),
 		        async:false,
 		        dataType: "json",
 		        success: function(data){
 		        	if(data.code=='0'){
 		        		layer.msg("操作成功", {icon: 1});
 		        		 parent.location.reload();	
 		    		} else {
 		    			layer.msg("操作失败", {icon: 0});
 		    		}
 		        }
 		    });
          }, function(){

          });
   });
    
    
    function openGneDiv(width, height, url, title) {
        $(window).one("resize", function () {
            var index2 = layui.layer.open({
                type: 2, 
                title: title,
                skin: 'layui-layer-molv',
                offset: 't',
                area: [width, height],
                content: url
            })
        }).resize();
        layer.close(0);
    }
    
	form.on('select(ideaCode)', function(data){
		if(data.value == "T"||data.value == "Z"){
			 bindUnitList(unitCode,data.value);
			$("#unitTr").show();
    	}else if (data.value == "J"){
    		 bindUnitList(unitCode,"J");
    		$("#unitTr").show();
    	}else{
    		$("#unitTr").hide();
    	}
	});
});